var common ={};
(function (){
	//获取url参数
	common.getURLParam=function(name){
		var regExp = new RegExp('(^|&)'+name +'=([^&]*)'+'(&|$)');
		var rs = window.location.search.substring(1).match(regExp);
		if(rs!= null) return decodeURI(rs[2]);
		else return '';
	}
	//获取cookie
	common.getCookie=function(name){
		var arr = document.cookie.match(new RegExp("(^| )"+encodeURI(name)+"=([^;]*)(;|$)"));
		if(arr!= null)
			return decodeURI(arr[2]);
		else
			return '';
	}
	common.getURLParamReg = function(name,flag){
		flag = flag||'&';
		var regExp = new RegExp('(^|' + flag + ')'+ name +'=([^' + flag + ']*)' + '(' + flag + '|$)');
		var rs = window.location.search.substring(1).match(regExp);
		if(rs!= null) return decodeURI(rs[2]);
		else return '';
	}
	/* 将字符串str用指定字符串pattern分割成num段 */
	common.splitin=function(str, pattern, num){
		var arr = [];
		if (num > 0) {
			var subindex = 0;
			for (var i = 0; i < num - 1; i++) {
				arr[i] = str.substring(subindex, str.indexOf(pattern, subindex));
				subindex = str.indexOf(pattern, subindex) + pattern.length;
			}
			arr.push(str.substring(subindex));
		} else {
			arr = str.split(pattern);
		}

		return arr;
	}
	//设置cookie
	common.setCookie=function(name,value,expires,path,domain)
	{
		var cookieStr = encodeURI(name) + '=' + encodeURI(value)+";";
		if(typeof expires != 'undefined'){
			if(typeof expires =='number')
			{
				var t = new Date();
				t.setDate(t.getDate()+expires);
				cookieStr += " expires=" + t.toUTCString() +";";
			}
			else
			{
				cookieStr += " expires=" + expires.toUTCString() +";";
			}
		}
		if(path)
		{
			cookieStr += " path=" + path + ";";
		}
		if(domain)
		{
			cookieStr+= " domain=" + domain + ";";
		}
		document.cookie=cookieStr;
	}
}())